package com.ygl.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@EnableDiscoveryClient
@SpringBootApplication
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                //basic proxy
                .route(r -> r.path("/login/**")
//                        .uri("lb://service-consumer")
                        .uri("http://www.baidu.com")
                        .id("xx")
                ).build();
//        return builder.routes()
//                .route(p -> p
//                        .path("/a/**")
////                        .filters(f -> f.addRequestHeader("Hello", "World"))
//                        .filters(f -> f.stripPrefix(1))
//                                .uri("lb://service-consumer")
//                )
//                .build();
    }
}
